home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / IO / TEST / LOCIO.C next >
C/C++ Source or Header  |  1997-01-25  |  4KB  |  161 lines

  1. #include <stdio.h>
  2. #include "time.h"
  3. #include "stdlib.h"
  4. #include "string.h"
  5.  
  6. /* STDINC stuff compatible with our sys */
  7.  
  8. /* CCFILE is the new definition, FILE is the BCC definition */
  9. typedef struct  {
  10.         int             level;          /* fill/empty level of buffer */
  11.         unsigned        flags;          /* File status flags          */
  12.         char            fd;             /* File descriptor            */
  13.         unsigned char   hold;           /* Ungetc char if no buffer   */
  14.                 char pad,pad1;                                    /* We need this to get BCC to define the
  15.                                                                                  * structure right */
  16.         int             bsize;          /* Buffer size                */
  17.         unsigned char   *buffer;   /* Data transfer buffer       */
  18.         unsigned char   *curp;     /* Current active pointer     */
  19.         unsigned        istemp;         /* Temporary file indicator   */
  20.         short           token;          /* Used for validity checking */
  21. }       CCFILE;                           /* This is the FILE object    */
  22.  
  23. #define _NFILE_ 100
  24.  
  25. extern FILE _streams[];
  26.  
  27. extern CCFILE *_PSTREAMS[_NFILE_];
  28. extern char *_FILENAMES[_NFILE_];
  29. extern int MAXFILES;
  30.  
  31. char inbuf[512];
  32. char outbuf[512];
  33. char errbuf[512];
  34.  
  35. #define FILTOK 0x444c
  36.  
  37. static CCFILE IN = {
  38.     0,_F_READ | _F_LBUF,0,0,0,0,512,&inbuf,&inbuf,0,FILTOK
  39. };
  40. static CCFILE OUT = {
  41.     0,_F_WRIT | _F_LBUF,1,0,0,0,512,&outbuf,&outbuf,0,FILTOK
  42. };
  43. static CCFILE ERR = {
  44.     0,_F_WRIT | _F_LBUF,2,0,0,0,512,&errbuf,&errbuf,0,FILTOK
  45. };
  46.  
  47. CCFILE *STDIN = &IN, *STDOUT = &OUT, *STDERR = &ERR;
  48.  
  49. /* REXIT is actually defined in the startup files and does not have to
  50.  * be written explicitly
  51.  */
  52. void _REXIT(void)
  53. {
  54.     exit(0);
  55. }
  56. void _LL_INIT(void)
  57. {
  58.     table[numopen++] = &_streams[0];    
  59.     table[numopen++] = &_streams[1];    
  60.     table[numopen++] = &_streams[2];
  61.     _PSTREAMS[MAXFILES++] = &IN;
  62.     _PSTREAMS[MAXFILES++] = &OUT;
  63.     _PSTREAMS[MAXFILES++] = &ERR;
  64. }
  65. int _LL_OPEN(char *__name, int flags)
  66. {
  67.     char buf[10],*p=buf;
  68.     if (flags & _F_READ)
  69.         *p++ = 'r';
  70.     if (flags & _F_BIN)
  71.         *p++ = 'b';
  72.     if (flags & _F_WRIT)
  73.         *p++ = '+';
  74.     *p = 0;
  75.     table[numopen] = fopen(__name,buf);
  76.     if (table[numopen])
  77.         return numopen++;
  78.     return 0;
  79. }
  80. int _LL_CREAT(char *__name, int flags)
  81. {
  82.     char buf[10],*p=buf;
  83.     if (flags & _F_WRIT)
  84.         *p++ = 'w';
  85.     if (flags & _F_BIN)
  86.         *p++ = 'b';
  87.     if (flags & _F_READ)
  88.         *p++ = '+';
  89.     *p = 0;
  90.     table[numopen] = fopen(__name,buf);
  91.     if (table[numopen])
  92.         return numopen++;
  93.     return 0;
  94. }
  95. int _LL_CLOSE(int __fd)
  96. {
  97.     int i;
  98.     fclose(table[__fd]);
  99.     for (i=__fd+1; i < numopen-1; i++)
  100.         table[i] = table[i+1];
  101.     numopen--;
  102.     return 0;
  103. }
  104. size_t _LL_GETPOS(int __fd)
  105. {
  106.     return ftell(table[__fd]);
  107. }
  108. int _LL_FLAGS(int __oldflags)
  109. {
  110.     return __oldflags;
  111. }
  112. int _LL_SEEK(int __fd, size_t __pos, int __origin)
  113. {
  114.     fseek(table[__fd],__pos,__origin);
  115.     return 0;
  116. }
  117. int _LL_RENAME(char *__old, char *__new)
  118. {
  119.     return rename(__old,__new);
  120. }
  121. int _LL_REMOVE(char *__name)
  122. {
  123.     return remove(__name);
  124. }
  125. int _LL_WRITE(int __fd,void *__buf,size_t __size)
  126. {
  127.     return !(fwrite(__buf,__size,1,table[__fd]) == __size);
  128. }
  129. int _LL_READ(int __fd,void *__buf,size_t __len)
  130. {
  131.     return fread(__buf,1,__len,table[__fd]);
  132. }
  133. void _LL_TRANSFER()
  134. {
  135. }
  136. void *_LL_MALLOC(size_t size)
  137. {
  138.     return(malloc(size));
  139. }
  140. void _LL_FREE(void *block)
  141. {
  142.     free(block);
  143. }
  144. struct tm *_LL_GETTIME(struct tm *tm2)
  145. {
  146.     time_t t = time(0);
  147.     *tm2 = *localtime(&t);
  148.     return tm2;
  149. }
  150. _LL_TICKS()
  151. {
  152.     return 0;
  153. }
  154. _LL_SYSTEM(char *name)
  155. {
  156.     return 0;
  157. }
  158. _LL_GETENV(void)
  159. {
  160.     return 0;
  161. }